package com.zyd.databindingdemo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.databinding.DataBindingUtil;

import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.material.snackbar.Snackbar;
import com.zyd.databindingdemo.databinding.ActivityLoginMainBinding;

public class LoginMainActivity extends AppCompatActivity {
    ActivityLoginMainBinding activityLoginMainBinding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activityLoginMainBinding = DataBindingUtil.setContentView(this, R.layout.activity_login_main);
        User user = new User();
        user.name.set("琉璃");
        user.age.set(24);

        activityLoginMainBinding.setUser(user);
        activityLoginMainBinding.setPassword("");
        activityLoginMainBinding.setLogin(new Login());

    }

    public class Login {
        public void onClick(View view) {
            if (view.getId() == R.id.alm_login) {
                User user = activityLoginMainBinding.getUser();
                String password = activityLoginMainBinding.getPassword();

                Log.i("Login", "password=" + password);

                if (user.name.get().equals("zyd") && password.equals("123123")) {
//                    Toast toast = Toast.makeText(LoginMainActivity.this, "登录成功！", Toast.LENGTH_SHORT);
//                    toast.setGravity(Gravity.BOTTOM, 0, 0);
//                    toast.show();
                    Snackbar.make(view,"登录成功！", Snackbar.LENGTH_SHORT).show();
                } else {
//                    Toast toast = Toast.makeText(LoginMainActivity.this, "登录失败！", Toast.LENGTH_SHORT);
//                    toast.setMargin(400,400);
//                    toast.show();
//                    Snackbar.make(view,"登录失败！", Snackbar.LENGTH_SHORT).show();

                    Snackbar snackbar = Snackbar.make(view, "Action 被点击", Snackbar.LENGTH_SHORT);
                    snackbar.setText("动态文本");//动态设置文本显示内容
                    snackbar.setActionTextColor(Color.RED);//动态设置Action文本的颜色
                    snackbar.setDuration(5000);//动态设置显示时间

                    snackbar.show();

                }
            }
            Log.i("Login", "onClick");
        }

    }
}